import java.util.Vector;

import static java.lang.Math.max;
import static java.lang.Math.min;

public class Tank {
    Vector<Bullet> vector = new Vector<>();
    Bullet bullet = null;

    public boolean isLife() {
        return life;
    }

    public void setLife(boolean life) {
        this.life = life;
    }

    private boolean life = true;
    Tank(int x, int y){
        this.x = x;
        this.y = y;
    }
    private int x;
    private int y;
    private int speed = 4;

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getDir() {
        return dir;
    }

    public void setDir(int dir) {
        this.dir = dir;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    private int dir;
    private int type;

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void attack(){
        if(vector.size() > 4) return;
        int xx, yy;
        switch (getDir()){
            case 0:
                xx = getX() + 15;
                yy = getY() - 10;
                break;
            case 1:
                xx = getX() - 10;
                yy = getY() + 15;
                break;
            case 2:
                xx = getX() + 15;
                yy = getY() + 55;
                break;
            default:
                xx = getX() + 55;
                yy = getY() + 15;
        }
        bullet = new Bullet(xx, yy, getDir());
        vector.add(bullet);
        Thread thread = new Thread(bullet);
        thread.start();
    }
    public void up(){
        y = max(y - speed, 0);
        y = min(y, 755);
        if(x == 1255) x = 1270;
    }
    public void left(){
        x = max(x - speed, 0);
        x = min(x, 1255);
        if(y == 755) y = 770;
    }
    public void right(){
        x = min(x + speed, 1255);
        if(y == 755) y = 770;
    }
    public void down(){
        y = min(y + speed, 755);
        if(x == 1255) x = 1270;
    }
}
